using System;
using System.Windows.Forms;
using System.Resources;
using System.Reflection;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;

namespace Microsoft.Samples.BizTalk.Adapter.Tcp.Setup.CustomActions
{
    [RunInstaller(true)]
    public partial class ShowFile : Installer
    {
        #region Private Instance Members

        private ResourceManager _resMgr;    // Resource manager used to access assembly resources

        #endregion

        #region Constructor

        /// <summary>
        ///     This is the default constructor for the class.
        /// </summary>
        public ShowFile()
        {
            InitializeComponent();

            // Initialize resource manager
            this._resMgr = new ResourceManager(ResourceConstants.BaseName, Assembly.GetExecutingAssembly());
        }

        #endregion

        #region Public Instance Methods

        /// <summary>
        ///     This method is called by the Installer when this custom action is being installed.
        /// </summary>
        public override void Install(System.Collections.IDictionary stateSaver)
        {
            // Call base implementation
            base.Install(stateSaver);

            // Get custom action parameters
            string text = this.Context.Parameters["text"];
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("text", this._resMgr.GetString(ResourceConstants.MustSpecifyHeaderText));
            }

            string file = this.Context.Parameters["file"];
            if (string.IsNullOrEmpty(file))
            {
                throw new ArgumentNullException("file", this._resMgr.GetString(ResourceConstants.MustSpecifyFileToLoad));
            }

            // Load dialog
            Microsoft.Samples.BizTalk.Adapter.Tcp.Setup.CustomActions.Forms.FileDialog dialog = new Microsoft.Samples.BizTalk.Adapter.Tcp.Setup.CustomActions.Forms.FileDialog();
            dialog.HeaderText = text;
            dialog.FilePath = file;
            dialog.ShowDialog();
        }

        #endregion
    }
}